package com.ruoyi.web.controller.youxuan;

import java.util.List;

import com.ruoyi.system.domain.YouxuanProductSaleDetail;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YouxuanOrder;
import com.ruoyi.system.service.IYouxuanOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单管理Controller
 * 
 * @author ruoyi
 * @date 2021-02-04
 */
@RestController
@RequestMapping("/youxuan/order")
public class YouxuanOrderController extends BaseController
{
    @Autowired
    private IYouxuanOrderService youxuanOrderService;

    /**
     * 查询订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('youxuan:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(YouxuanOrder youxuanOrder)
    {
        startPage();
        List<YouxuanOrder> list = youxuanOrderService.selectYouxuanOrderList(youxuanOrder);
        return getDataTable(list);
    }
    @GetMapping("/listProductDetail")
    public TableDataInfo listProductDetail(YouxuanProductSaleDetail youxuanProductSaleDetail)
    {
        startPage();
        List<YouxuanProductSaleDetail> list = youxuanOrderService.selectYouxuanProductSaleDetailList(youxuanProductSaleDetail);
        return getDataTable(list);
    }
    /**
     * 导出订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('youxuan:order:export')")
    @Log(title = "订单管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(YouxuanOrder youxuanOrder)
    {
        List<YouxuanOrder> list = youxuanOrderService.selectYouxuanOrderList(youxuanOrder);
        ExcelUtil<YouxuanOrder> util = new ExcelUtil<YouxuanOrder>(YouxuanOrder.class);
        return util.exportExcel(list, "order");
    }


    /**
     * 获取订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('youxuan:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return AjaxResult.success(youxuanOrderService.selectYouxuanOrderById(orderId));
    }

    /**
     * 新增订单管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:order:add')")
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YouxuanOrder youxuanOrder)
    {
        return toAjax(youxuanOrderService.insertYouxuanOrder(youxuanOrder));
    }

    /**
     * 修改订单管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:order:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YouxuanOrder youxuanOrder)
    {
        return toAjax(youxuanOrderService.updateYouxuanOrder(youxuanOrder));
    }

    /**
     * 删除订单管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:order:remove')")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(youxuanOrderService.deleteYouxuanOrderByIds(orderIds));
    }
}
